import { http } from "@/utils/http";

// 公告基础类型
export interface NoticeBase {
  id?: number;
  noticeName: string;
  noticeType: string;
  cellId: number;
  status: string;
  publisher: string;
  content: string;
  isTop: number;
  createTime?: string;
  updateTime?: string;
  tenantId?: number;
}

// 新增公告DTO
export interface InsertNoticeDto {
  id?: number;
  // 公告标题
  noticeName: string;
  // 公告类型（如：普通、通知、提醒等）
  noticeType: string;
  // 小区ID
  cellId: number;
  // 公告状态（如：草稿、已发布）
  status: string;
  // 发布人姓名
  publisher: string;
  // 公告内容
  content: string;
  // 是否置顶（1：置顶，0：不置顶）
  isTop: number;
}

// 更新公告DTO
export interface UpdateNoticeDto {
  id: number;
  noticeName: string;
  noticeType: string;
  cellId: number;
  status: string;
  publisher: string;
  content: string;
  isTop: number;
  tenantId?: number;
}

// 查询公告DTO
export interface NoticeQueryDto {
  noticeName?: string;
  noticeType?: string;
  content?: string;
  tenantId?: number;
  status?: string;
  isTop?: number;
  cellId?: number;
  publisher?: string;
  pageNum?: number;
  pageSize?: number;
}

// 批量删除DTO
export interface BaseDeleteDto {
  ids: number[];
}

// 通用响应类型
export interface ApiResult<T = any> {
  code: number;
  data: T;
  message: string;
}

// 分页响应类型
export interface PageResult<T = any> {
  records: T[];
  total: number;
}

// 新增公告
export const addNotice = (
  data: InsertNoticeDto
): Promise<ApiResult<NoticeBase>> => {
  return http.request<ApiResult<NoticeBase>>("post", "/notice/add", { data });
};

// 批量删除公告
export const deleteNotices = (deleteData: BaseDeleteDto) => {
  return http.request<ApiResult<BaseDeleteDto>>("post", "/notice/deleteByIds", {
    data: deleteData
  });
};

// 更新公告
export const updateNotice = (updateData: UpdateNoticeDto) => {
  return http.request<ApiResult<NoticeBase>>("post", "/notice/update", {
    data: updateData
  });
};

// 查询单个公告
export const getNoticeById = (noticeId: number) => {
  return http.request<ApiResult<NoticeBase>>("get", "/notice/queryById", {
    params: { id: noticeId }
  });
};

// 查询所有公告
export const getAllNotices = () => {
  return http.request<ApiResult<NoticeBase[]>>("get", "/notice/queryAll");
};

// 模糊查询公告
export const queryNotices = (queryData: NoticeQueryDto) => {
  return http.request<ApiResult<PageResult<NoticeBase>>>(
    "get",
    "/notice/queryByDto",
    { params: queryData }
  );
};

// 发布公告
export const publishNotice = (noticeId: number) => {
  return http.request<ApiResult>("get", "/notice/publish", {
    params: { id: noticeId }
  });
};
